package cn.biplam.common.client;

import java.rmi.RemoteException;

import cn.biplam.common.interfaces.DataOperatorServer;
import cn.biplam.common.tools.RMITOOLS;
import cn.biplam.common.wrapper.ErrorMessage;

public abstract class ClassUtil {

	
	/**
	 * 返回实现类的接口对象(无参构造)
	 * @param className 接口的实现类名称
	 * @return 实现类的接口对象
	 * @throws RemoteException
	 * @throws ErrorMessage
	 */
	public static Object get(String className) throws ErrorMessage {
		Object obj = null;

		try {
			DataOperatorServer mDataOperatorServer = (DataOperatorServer)RMITOOLS.getInstance("DataOperatorServer");
			obj = mDataOperatorServer.get(className);
		} catch (ErrorMessage e) {
			throw e;
		} catch (RemoteException e) {
			throw new ErrorMessage(e);
		}
		return obj;
	}
	
	/**
	 * 返回实现类的接口对象(有参构造)
	 * @param className 接口的实现类名称
	 * @param classParams  构造方法参数
	 * @return 实现类的接口对象
	 * @throws RemoteException
	 * @throws ErrorMessage
	 */
	public static Object get(String className,
							 Object... classParams) throws ErrorMessage {
		Object obj = null;

		try {
			DataOperatorServer mDataOperatorServer = (DataOperatorServer)RMITOOLS.getInstance("DataOperatorServer");
			obj = mDataOperatorServer.get(className,classParams);
		} catch (ErrorMessage e) {
			throw e;
		} catch (RemoteException e) {
			throw new ErrorMessage(e);
		}
		return obj;
	}
}
